package org.gap.web.jsf;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.gap.dao.CaractPPDAO;
import org.gap.dao.TiersDAO;

import org.gap.domain.CaractPP;
import org.gap.domain.Tiers;

import org.gap.service.CaractPPService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for CaractPP entities
 * 
 */
@Scope("session")
@Component("CaractPPComponent")
public class CaractPPComponentImpl implements CaractPPComponent {

	/**
	 * Data type variable that provides CRUD operations for CaractPP entities
	 * 
	 */
	private CaractPP caractpp;

	/**
	 * DAO injected by Spring that manages Tiers entities
	 * 
	 */
	private Tiers tiers;

	/**
	 * DAO injected by Spring that manages CaractPP entities
	 * 
	 */
	@Autowired
	private CaractPPDAO caractPPDAO;

	/**
	 * DAO injected by Spring that manages Tiers entities
	 * 
	 */
	@Autowired
	private TiersDAO tiersDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for CaractPP entities
	 * 
	 */
	@Autowired
	private CaractPPService caractPPService;

	/** 
	 */
	public CaractPPComponentImpl() {
	}

	/**
	 * Create a new Tiers entity
	 * 
	 */
	@Transactional
	public String newCaractPPTiers(Integer caractpp_cppTiers) {
		tiers = new Tiers();

		return "/jsf/caractpp/tiers/createTiers.xhtml";
	}

	/**
	 * Save an existing CaractPP entity
	 * 
	 */
	@Transactional
	public String saveCaractPP(CaractPP caractpp) {
		caractPPService.saveCaractPP(caractpp);
		return "/jsf/caractpp/listCaractPPs.xhtml";
	}

	/**
	 * Select the CaractPP entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteCaractPP(Integer cppTiersKey) {
		caractpp = caractPPDAO.findCaractPPByPrimaryKey(cppTiersKey);

		return "/jsf/caractpp/deleteCaractPP.xhtml";
	}

	/**
	 * Select the child Tiers entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteCaractPPTiers(Integer caractpp_cppTiers, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers);

		return "/jsf/caractpp/tiers/deleteTiers.xhtml";
	}

	/**
	 * Create a new CaractPP entity
	 * 
	 */
	@Transactional
	public String newCaractPP() {
		caractpp = new CaractPP();

		return "/jsf/caractpp/createCaractPP.xhtml";
	}

	/**
	 * Edit an existing CaractPP entity
	 * 
	 */
	@Transactional
	public String editCaractPP(Integer cppTiersKey) {
		caractpp = caractPPDAO.findCaractPPByPrimaryKey(cppTiersKey);

		return "/jsf/caractpp/editCaractPP.xhtml";
	}

	/**
	 * Get Tiers entity by CaractPP
	 * 
	 */
	@Transactional
	public Tiers getCaractPPTiers(Integer cppTiersKey) {
		return caractPPDAO.findCaractPPByPrimaryKey(cppTiersKey).getTiers();
	}

	/**
	 * View an existing Tiers entity
	 * 
	 */
	@Transactional
	public String selectCaractPPTiers(Integer caractpp_cppTiers, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers, -1, -1);
		return "/jsf/caractpp/tiers/viewTiers.xhtml";
	}

	/**
	 * Delete an existing Tiers entity
	 * 
	 */
	@Transactional
	public String deleteCaractPPTiers(Integer caractpp_cppTiers, Integer related_tiers_tieTiers) {
		caractpp = caractPPService.deleteCaractPPTiers(caractpp_cppTiers, related_tiers_tieTiers);

		return "/jsf/caractpp/viewCaractPP.xhtml";
	}

	/**
	 * Select an existing CaractPP entity
	 * 
	 */
	@Transactional
	public String selectCaractPP(Integer cppTiersKey) {
		caractpp = caractPPDAO.findCaractPPByPrimaryKey(cppTiersKey);

		return "/jsf/caractpp/viewCaractPP.xhtml";
	}

	/**
	 * Edit an existing Tiers entity
	 * 
	 */
	@Transactional
	public String editCaractPPTiers(Integer caractpp_cppTiers, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers, -1, -1);
		return "/jsf/caractpp/tiers/editTiers.xhtml";
	}

	/**
	 * Show all CaractPP entities
	 * 
	 */
	@Transactional
	public List<CaractPP> listCaractPPs() {
		return new java.util.ArrayList<CaractPP>(caractPPService.loadCaractPPs());
	}
	
	/**
	 * Show CaractPP entities by Name
	 * 
	 */
	@Transactional
	public List<CaractPP> listCaractPPsByName(String inputName) {
		return new java.util.ArrayList<CaractPP>(caractPPService.loadCaractPPsByName(inputName));
	}

/***
 * 
 * 
 * 
 */
	public List<String> loadNamePersonnne(){
		
		return new ArrayList<String>(caractPPService.loadNamePers());
	}
	
	/**
	 * Getter for variable CaractPP
	 * 
	 */
	@Transactional
	public CaractPP getCaractpp() {
		return caractpp;
	}

	/**
	 * Save an existing Tiers entity
	 * 
	 */
	@Transactional
	public String saveCaractPPTiers(Integer caractpp_cppTiers, Tiers tiers) {
		caractpp = caractPPService.saveCaractPPTiers(caractpp_cppTiers, tiers);

		return "/jsf/caractpp/viewCaractPP.xhtml";
	}

	/**
	 * Delete an existing CaractPP entity
	 * 
	 */
	@Transactional
	public String deleteCaractPP(Integer cppTiersKey) {
		CaractPP caractpp = caractPPDAO.findCaractPPByPrimaryKey(cppTiersKey);
		caractPPService.deleteCaractPP(caractpp);
		return "/jsf/caractpp/listCaractPPs.xhtml";
	}

	/**
	 * Getter for variable CaractPP
	 * 
	 */
	@Transactional
	public Tiers getTiers() {
		return tiers;
	}
/*
	public List<CaractPP> selectCPPByNameAndFirstname(String inputValue) {
		java.util.ArrayList<CaractPP> caractpp = (ArrayList<CaractPP>) caractPPDAO.findCaractPPByCppNomPersAndPrenomPers(inputValue);
		java.util.ArrayList<CaractPP> caractpp;
		return caractpp;
		
		//return "/jsf/caractpp/listCaractPPs.xhtml";
	}
*/

	

	
	
}
